package com.chb.microservice.provider.hystrix;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;

import com.cbh.api.model.ApiResult;
import com.chb.microservice.provider.feign.AreaFeignClient;
import com.chb.microservice.provider.model.Area;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

@Service
public class AreaHystrixWrapped {

	@Autowired
	private AreaFeignClient generalFeignClient;

	@HystrixCommand(groupKey = "helloGroup", fallbackMethod = "fallBackCall")
	public ApiResult<String> save(Area ob) {
		return generalFeignClient.save(ob);
	};

	public ApiResult<String> fallBackCall(Area ob) {
		return new ApiResult<String>().fail("调用出错");
	}

	/**
	 * 获取全部开放区域信息
	 * 
	 * @return
	 */
	@HystrixCommand(groupKey = "helloGroup", fallbackMethod = "fallBackCall")
	public ApiResult<List<Area>> getAll() {
		return generalFeignClient.getAll();
	}

	public ApiResult<List<Area>> fallBackCall() {
		return new ApiResult<List<Area>>().fail("调用出错");
	}

	/**
	 * 获取开放区域信息
	 * 
	 * @param proId
	 * @return
	 */
	@HystrixCommand(groupKey = "helloGroup", fallbackMethod = "fallBackCall")
	public ApiResult<Area> getOne(@PathVariable("id") String id) {
		return generalFeignClient.getOne(id);
	}

	public ApiResult<Area> fallBackCall(String id) {
		return new ApiResult<Area>().fail("调用出错");
	}

}
